package site.marqstree.kotlin.library.base.util.callback

import java.util.*


/*
 * 项目名: KotlinMall
 * 包名: site.marqstree.kotlin.library.base.util.callback
 * 文件名: CallbackManager
 * 创建者: marqstree
 * 创建时间: 2020/3/8 12:07
 * 描述: TODO
 */
class CallbackManager {
    private object Holder {
        val INSTANCE = CallbackManager()
    }

    fun addCallback(tag: Any, callback: IGlobalCallback<*>): CallbackManager {
        CALLBACKS[tag] = callback
        return this
    }

    fun getCallback(tag: Any): IGlobalCallback<*>? {
        return CALLBACKS[tag]
    }

    companion object {
        private val CALLBACKS: WeakHashMap<Any, IGlobalCallback<*>> =
            WeakHashMap<Any, IGlobalCallback<*>>()

        val instance: CallbackManager
            get() = Holder.INSTANCE
    }
}